//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
  return {
    windForm:{
      bank_card_no:'',
      bank_province_id:'',
      bank_city_id:'',
      bank_province_name:'',
      bank_city_name:'',
      id_front_pic:'',
      id_behind_pic:'',
      bank_card_before_pic:'',
      bank_card_behind_pic:''
    },
    fileList:[],
    fileList2:[],
    fileList3:[],
    fileList4:[],
    uploadUrl: "upload.uploadPic", //上传图片
    addressName:'',
    addressShow:false,
    //街道
    area: district,
    selectImgIndex: "",
    stopButton: false,
    succeedRadio:'1',
    withdrawInfo:{},
    iPnoneBottomBol: false, //是否是苹果手机
    windStatus:0,
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getiPnoneBottom() { //检测是否为苹果手机
      var userAgent = navigator.userAgent;
      var isiOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      isiOS?this.iPnoneBottomBol = true:this.iPnoneBottomBol = false;
    },
    // 地址回调
    addressCallback(obj) {
      this.addressName = obj.itemName1 + " " + obj.itemName2;
      console.log(obj);
      this.windForm.bank_province_name = obj.itemName1;
      this.windForm.bank_province_id = obj.itemValue1;
      this.windForm.bank_city_name = obj.itemName2;
      this.windForm.bank_city_id = obj.itemValue2;
    },
    userAccountTo() {
      if (window.history.length <= 1) {
        this.$router.push(this.fun.getUrl("home", {}));
      } else {
        this.$router.go(-1);
      }
    },
    windSetOn() {
      this.windStatus = 2;
    },
    withdrawData() {
      $http.get("plugin.integration-pay-share.frontend.withdraw.index",{}, "加载中..").then(res => {
        if (res.result == 1) {
          let data = res.data; //没有数据返回的是一个空数组
          console.log(data);
          if(!Array.isArray(data)) {
            this.withdrawInfo = data;
            let settleInfo = data.has_one_active_settle_info;
            if(settleInfo) {
              this.windStatus = 1;
              this.windForm.bank_card_no = settleInfo.bank_card_no;
              this.windForm.bank_province_id = settleInfo.bank_province_id;
              this.windForm.bank_city_id = settleInfo.bank_city_id;
              this.windForm.bank_province_name = settleInfo.bank_province_name;
              this.windForm.bank_city_name = settleInfo.bank_city_name;
              this.windForm.id_front_pic = settleInfo.id_front_pic;
              this.windForm.id_behind_pic = settleInfo.id_behind_pic;
              this.windForm.bank_card_before_pic = settleInfo.bank_card_before_pic;
              this.windForm.bank_card_behind_pic = settleInfo.bank_card_behind_pic;
              this.addressName = settleInfo.bank_province_name + settleInfo.bank_city_name;
              console.log(this.fileList);
              if(settleInfo.id_front_pic) {
                this.fileList.push({url:settleInfo.id_front_pic});
              }
              if(settleInfo.id_behind_pic) {
                this.fileList2.push({url:settleInfo.id_behind_pic});
              }
              if(settleInfo.bank_card_before_pic) {
                this.fileList3.push({url:settleInfo.bank_card_before_pic});
              }
              if(settleInfo.bank_card_behind_pic) {
                this.fileList4.push({url:settleInfo.bank_card_behind_pic});
              }
            }
            
            // this.$toast(data.settle_status);
          }
        } else {
          this.$dialog.alert({
            message: res.msg
          });
        }
      });
    },
    onAddress() {
      this.addressShow = true;
    },
    /*vant图片上传*/
    onRead(e, flag) {
      this.$toast.loading({
        message: "上传中",
        forbidClick: true
      });
      this.stopButton = true;
      let fd = new FormData();

      if (flag === true) {
        fd.append("file", e); // 第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      } else {
        fd.append("file", e.file); // 第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      }
      var That = this;
      axios
        .post(this.uploadUrl, fd, {
          headers: { "Content-Type": "multipart/form-data" }
        })
        .then(response => {
          var responseData = response.data;
          if (responseData.result === 1) {
            this.$toast.clear();
            switch (this.selectImgIndex) {
              case 1:
                this.windForm.id_front_pic = responseData.data.img_url;
                console.log(this.windForm.id_front_pic);
                this.stopButton = false;
                break;
              case 2:
                this.windForm.id_behind_pic = responseData.data.img_url;
                this.stopButton = false;
                break;
              case 3:
                this.windForm.bank_card_before_pic = responseData.data.img_url;
                this.stopButton = false;
                break;
              case 4:
                this.windForm.bank_card_behind_pic = responseData.data.img_url;
                this.stopButton = false;
                break;
                default:
                  That.stopButton = false;
                  return;
            }
          } else {
            // Toast(responseData.msg);
            this.$toast(responseData.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    selectIndex(i) {
      if (this.stopButton) {
        return false;
      }
      this.selectImgIndex = i;
    },
    windSubmit() {
      $http.post("plugin.integration-pay-share.frontend.withdraw.set-settle-info", {form:this.windForm}, "加载中..").then(res => {
        if (res.result == 1) {
          let data = res.data;
          this.$toast(res.msg);
          this.initData();
          this.withdrawData();
          setTimeout(() => {
            this.$router.replace(this.fun.getUrl("member",{}));//需要先签署合同
          },1000);
        } else {
          this.$dialog.alert({
            message: res.msg
          });
        }
      });
    },
    initData() {
      this.fileList = [];
      this.fileList2 = [];
      this.fileList3 = [];
      this.fileList4 = [];
    }

  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.uploadUrl = this.fun.getRealUrl("upload.uploadPic", {});
    this.withdrawData();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}